package com.summer_administration.mapper;

import com.summer_administration.pojo.CommuneArrange;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface CommuneArrangeMapper {
    @Insert("INSERT INTO commune_arrange(commune, time, address,group_id,group_name,vol_number, " +
            "children_num, age_group, facility, prize, create_user, create_time, update_time) " +
            "VALUES(#{commune}, #{time}, #{address},#{groupId},#{groupName}, #{volNumber}, #{childrenNum}, " +
            "#{ageGroup}, #{facility}, #{prize}, #{createUser}, #{createTime}, #{updateTime})")
    void add(CommuneArrange arrange);

    @Select("<script>" +
            "SELECT * FROM commune_arrange " +
            "WHERE create_user = #{userId} " +
            "</script>")
    List<CommuneArrange> list(Integer userId);

    @Update("UPDATE commune_arrange SET commune=#{commune}, time=#{time}, address=#{address}, " +
            "group_name=#{groupName}, vol_number=#{volNumber}, children_num=#{childrenNum}, " +
            "age_group=#{ageGroup}, facility=#{facility}, prize=#{prize}, update_time=#{updateTime} " +
            "WHERE id=#{id}")
    void update(CommuneArrange arrange);

    @Delete("DELETE FROM commune_arrange WHERE id=#{id}")
    void delete(Integer id);

    @Select("SELECT * FROM commune_arrange WHERE id = #{id}")
    CommuneArrange getById(Integer id);

    @Select("SELECT * FROM commune_arrange WHERE group_id = #{groupId} ORDER BY time ASC")
    List<CommuneArrange> getByGroupIdOrderByTime(String groupId);
}